<!DOCTYPE html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>{:ZMCMS_VERSION}-后台登录管理</title>
    <link rel="stylesheet" href="/static/admin/login/css/login.css">
<script>
if(window.top.location != window.self.location){
	window.top.location = window.self.location;
}
window.onload=function(){
		document.getElementById("username").focus();
}
</script>       
</head>
<body>
<div class="login">
    <div class="login_title">
        <p><img src="/static/admin/login/images/sysUser.png" ></p>
    </div>
    <div class="login_main">

        <div class="main_right">
            <div class="right_title">管理登录</div>
            <form action="{:url(SYS_PATH."/Login/index")}" method="post" name="sysLogin" id="sysLogin">
                <div class="username">
                    <img src="/static/admin/login/images/username.png" alt="">
                    <input type="text" name="username" id="username" placeholder="请输入用户名">
                </div>
                <div class="password">
                    <img src="/static/admin/login/images/password.png" alt="">
                    <input type="password" name="passwd" id="passwd" placeholder="请输入密码">
                </div>

                <div class="code">
                    <img src="/static/admin/login/images/code.png" alt="">
                    <input type="text" name="code" id="code" placeholder="请输入验证码">
                    <div class="code_img">
                        <img src="{:url(SYS_PATH."/Login/verify")}" class="login-captcha"  alt="">
                    </div>
                </div>

                <div class="yes_login"><input type="button" id="sysLoginButton" value="登录"></div>
            </form>
        </div>
        
    </div>

    <div class="login_footer">
        <p class="name">  系统版本：{:ZMCMS_VERSION}</p>
        <p>建议浏览器：IE9以上、Firefox v22</p>
    </div>
</div>
<script type="text/javascript" src="/static/admin/login/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script language="javascript">
$(document).ready(function() {
    $("#sysLoginButton").click(function () {
    	var uri="{:url(SYS_PATH."/Login/index")}";
        var txtUser = $.trim($("#username").val());
        var txtPwd = $("#passwd").val();
        
        if ($.trim(txtUser) == "") {
            $("#username").focus();
            layer.msg('请输入账号',{time:1000,icon:2});
            return false;
        }
        if ($.trim(txtPwd) == "") {
            $("#passwd").focus();
            layer.msg('请输入密码',{time:1000,icon:2});
            return false;
        }
		var txtCode = $.trim($('#code').val());
        if ($.trim(txtCode) == "") {
            $("#code").focus();
            layer.msg('请输入验证码',{time:1000,icon:2});
            return false;
        }
 		layer.load(2,{shade: [0.5,'#fff']});
		var field={"username":txtUser,"passwd":txtPwd,"code":txtCode};
        $.ajax({
                url: uri,
                data: field,
                type: 'POST',
                dataType: 'JSON',
                success: function (res) {
                   //console.log(JSON.stringify(res));
				   //alert(res.code);
				   if(res.code==0){
                        layer.msg('登录成功', {icon: 1, time: 500}, function () {
                            location.replace('../');
                        });						
					}else {
                        layer.closeAll('loading');
                       	$('.login-captcha').attr("src",$('.login-captcha').attr("src")+"&t"+(new Date()).getTime());
					   	$('.login-captcha').focus();
                        layer.msg(res.msg, {icon: 2,time:500});
                    }
                },
                error: function (xhr) {
                    layer.closeAll('loading');
                    if (xhr.status == 400) {
                        layer.msg('账号或密码错误', {icon: 2,time:500});
                    }
                }
            });
		return false;
    });
    // 图形验证码
    $('.login-captcha').click(function () {
        this.src = this.src + '?t=' + (new Date).getTime();
    });	
	
	$(".login").bind("keydown",function(e){
			// 兼容FF和IE和Opera    
		var theEvent = e || window.event;    
		var code = theEvent.keyCode || theEvent.which || theEvent.charCode;    
		if (code == 13) {    
			//回车执行查询
				$("#sysLoginButton").click();
			}    
	});	
	
});
</script>
</body>
</html>